package com.fcx.workai.jinchang.ui.mine_drawer.mysetting;

import android.os.Bundle;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hxh.component.basicore.Base.topbar.ActionBarConfig;
import com.hxh.component.basicore.component.mvp.persenter.IPresenter;
import com.hxh.component.basicore.util.Utils;
import com.hxh.component.business.app.App;
import com.hxh.component.business.arouter.MyAppProvider;
import com.hxh.component.business.ui.MyUtil;
import com.hxh.component.business.ui.TopBarBaseLazyFragment;
import com.hxh.component.business.utils.Constant;
import com.hxh.component.ui.alertview.OnItemClickListener;

import com.fcx.workai.jinchang.R;
import com.fcx.workai.jinchang.ui.mine_drawer.mysetpwd.MineSetPwdFragment;


/**
 * author mardawang
 * <p>
 * email:wy363681759@163.com
 * <p>
 * date: 2018/2/2
 * <p>
 * desc:
 */

public class MineSettingFragment extends TopBarBaseLazyFragment{

    private TextView mTv_version;
    private RelativeLayout mRl_pwd_set;
    private TextView tv_exit;

    public static MineSettingFragment newInstance() {

        Bundle args = new Bundle();

        MineSettingFragment fragment = new MineSettingFragment();
        fragment.setArguments(args);
        return fragment;
    }

    @Override
    protected ActionBarConfig setActionBarConfig() {
        return new ActionBarConfig.Builder()
                .enableBackView()
                .title("设置", R.color.black)
                .backgroundColor(R.color.white)
                .build();
    }

    @Override
    public int getLayoutId() {
        return R.layout.fragment_mine_setting;
    }

    @Override
    public void initData(Bundle bundle) {
        mTv_version = (TextView) findViewBy(R.id.tv_version);
        mRl_pwd_set = (RelativeLayout) findViewBy(R.id.rl_pwd_set);
        tv_exit = (TextView) findViewBy(R.id.tv_exit);

        mTv_version.setText("V"+Utils.Package.getVersionName());
        mRl_pwd_set.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                start( MineSetPwdFragment.newInstance());
//                startActivity(MineMainActivity.class, Constant.RouterTag.SHOWTAG, Constant.RouterTag.MINE_SET_PWD);
            }
        });

        tv_exit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                MyUtil.DialogUtils.showDefaulStyleDialog("\n退出登录", "取消", "确定", new OnItemClickListener() {
                    @Override
                    public void onItemClick(String item, int position) {
                        if(position == 0)
                        {
                            Utils.SP.editor().remove(Constant.SpTag.COMPANY_NAME).commit();
                            Utils.SP.editor().remove(Constant.SpTag.COMPANY_ID).commit();
                            Utils.SP.editor().remove(Constant.SpTag.COMPANY_BEAN).commit();
                            MyAppProvider.startLoginActivty(Constant.RouterTag.SHOWTAG, Constant.RouterTag.LOGIN_SHOWTYPE_SMSLOGIN);
                            App.getUserDTO().setUser(null);
                            getActivity().finish();
                        }
                    }
                }).show();
            }
        });
    }

    @Override
    public IPresenter newP() {
        return null;
    }
}
